package nl.saxion.ein4b.model;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author Rick
 * 
 */
public class CardStack {

	/**
	 * 
	 */
	private ArrayList<Card> cards = new ArrayList<Card>();
	private boolean hasBeenSplit = false;
	private int splitStackValue = 0;

	/**
	 * 
	 */
	public void createCardStack() {
		for (CardColor cardColor : CardColor.values()) {
			for (CardType cardType : CardType.values()) {
				cards.add(new Card(cardType, cardColor));
				cards.trimToSize();
			}
		}
		Collections.shuffle(cards);
	}

	/**
	 * @return
	 */
	public Card pop() {
		Card card = cards.get(0);
		cards.remove(0);
		cards.trimToSize();
		return card;
	}

	/**
	 * @param card
	 */
	public void push(Card card) {
		cards.add(card);
	}

	/**
	 * @return possible values for the current cards in the stack, taking in
	 *         account every ace.
	 */
	public ArrayList<Integer> getPossibleValues() {
		ArrayList<Integer> values = new ArrayList<Integer>();
		values.add(0);
		for (Card c : cards) {
			int v = c.getcardType().getValue();
			if (v == 1) {
				int vs = values.size();
				for (int i = 0; i < vs; i++) {
					if (!values.contains(values.get(i) + 10))
						values.add(values.get(i) + 11);
					values.set(i, values.get(i) + 1);
				}
			} else {
				for (int i = 0; i < values.size(); i++) {
					values.set(i, values.get(i) + v);
				}
			}
		}
		return values;
	}

	public void setSplitStackValue(int value) {
		splitStackValue = value;
	}

	public int getSplitStackValue() {
		return splitStackValue;
	}

	public boolean isSplit() {
		return hasBeenSplit;
	}

	public void setSplit() {
		hasBeenSplit = true;
	}

	/**
	 * @return
	 */
	public ArrayList<Card> getCardStack() {
		return cards;
	}
}
